{extend name="common/application" /}
{block name="title"}<title>搜索中心</title>{/block}
{block name="css"}

<link rel="stylesheet" type="text/css" href="_CSS_/reset.css">
<link rel="stylesheet" type="text/css" href="_CSS_/common.css">
<link rel="stylesheet" type="text/css" href="_CSS_/slide.css">
<link rel="stylesheet" type="text/css" href="_CSS_/search_work.css">
<link rel="stylesheet" type="text/css" href="_CSS_/scom.css"/>
<!--[if lt IE 9]>
<script src="http://www.ijquery.cn/js/html5shiv.js"></script>
<![endif]-->
{/block}

{block name="content"}
<!-- 主体内容 -->
<div class="main">
    <div class="mainBody normalBox clearfix" style="padding-top: 0px;">
        <div class="courses sectionArea normalBox" style="margin-top: 0px;">
            <!--搜索类别-->
            <div class="courseMenu">
                {include file="/common/course" /}
            </div>
            <!--查询不出数据-->
            <div class="nodatas" style="display: none;">
                <img src="/static/web/images/nodata.png"/>
                <p>抱歉，找不到相关数据</p>
            </div>
            <!--相关商品-->
            <div class="con-part government-part">
                <div class="con-title">
                    <p class="sectionName fl">
                        <span class="icons icon-sg"></span>
                        <span>相关商品</span>
                        <span class="sec-num"></span>
                    </p>

                    <a class="readMore fr" href="javascript:void(0);"><input type="hidden" id="value">查看更多<span
                            class="icons icon-right"></span></a>
                    <p class="sel-btnbox fr">
                        <a class="seled-btn" href="javascript:void(0);">交易市场</a>
                        <a class="" href="javascript:void(0);">服务市场</a>
                    </p>
                </div>
                <div class="conBody">
                </div>
            </div>
            <!--相关店铺-->
            <div class="con-part government-part">
                <div class="con-title">
                    <p class="sectionName fl">
                        <span class="icons icon-ss"></span>
                        <span>相关店铺</span>
                        <span class="sec-num"></span>
                    </p>
                    <a class="readMore fr" href="javascript:void(0);">查看更多<span class="icons icon-right"></span></a>
                </div>
                <div class="conBody">
                </div>
            </div>
            <!--相关课程-->
            <div class="con-part">
                <div class="con-title">
                    <p class="sectionName fl">
                        <span class="icons icon-course"></span>
                        <span>相关课程</span>
                        <span class="sec-num"></span>
                    </p>
                    <a class="readMore fr" href="javascript:void(0);">查看更多<span class="icons icon-right"></span></a>
                </div>
                <div class="conBody">

                </div>
            </div>
            <!--相关人才-->
            <div class="con-part personnels">
                <div class="con-title">
                    <p class="sectionName fl">
                        <span class="icons icon-sgo"></span>
                        <span>相关人才</span>
                        <span class="sec-num"></span>
                    </p>
                    <a class="readMore fr" href="javascript:void(0);">查看更多<span class="icons icon-right"></span></a>
                </div>
                <div class="conBody">
                </div>
            </div>
            <!--相关师资-->
            <div class="con-part teachers">
                <div class="con-title">
                    <p class="sectionName fl">
                        <span class="icons icon-teachers"></span>
                        <span>相关师资</span>
                        <span class="sec-num"></span>
                    </p>
                    <a class="readMore fr" href="javascript:void(0);">查看更多<span class="icons icon-right"></span></a>
                </div>
                <div class="conBody">
                </div>
            </div>
            <!--相关政务-->
            <div class="con-part government-part">
                <div class="con-title">
                    <p class="sectionName fl">
                        <span class="icons icon-early"></span>
                        <span>相关政务</span>
                        <span class="sec-num"></span>
                    </p>
                    <a class="readMore fr" href="javascript:void(0);">查看更多<span class="icons icon-right"></span></a>
                </div>
                <div class="conBody" style="padding-top:20px;">
                </div>
            </div>
        </div>
    </div>
</div>

{/block}
{block name="js"}
<!-- 脚本引入 -->

<script src="_JS_/jquery.SuperSlide.2.1.2.js"></script>
<script src="_P_/layer/layer.js"></script>
<script src="_JS_/jquery.qrcode.min.js"></script>
<script src="_JS_/train_details.js"></script>
<script type="text/javascript" src="_JS_/getMyDate.js"></script>
<script type="text/javascript">
    $('#sel_0').addClass('selected');
    $("a.selectType").eq(0).on('click', function () {
        var keyword = decodeURI(window.location.href.split("?")[1]);
        window.location.href = "{:url('index/search/search_work')}?" + keyword;
    });
    $("a.selectType").eq(1).on('click', function () {
        var keyword = decodeURI(window.location.href.split("?")[1]);
        window.location.href = "{:url('index/search/search_trade')}?" + keyword;
    });
    $("a.selectType").eq(2).on('click', function () {
        var keyword = decodeURI(window.location.href.split("?")[1]);
        window.location.href = "{:url('index/search/search_store')}?" + keyword;
    });
    $("a.selectType").eq(3).on('click', function () {
        var keyword = decodeURI(window.location.href.split("?")[1]);
        window.location.href = "{:url('index/search/search_courses')}?" + keyword;
    });
    $("a.selectType").eq(4).on('click', function () {
        var keyword = decodeURI(window.location.href.split("?")[1]);
        window.location.href = "{:url('index/search/search_persons')}?" + keyword;
    });
    $("a.selectType").eq(5).on('click', function () {
        var keyword = decodeURI(window.location.href.split("?")[1]);
        window.location.href = "{:url('index/search/search_teachers')}?" + keyword;
    });
    $("a.selectType").eq(6).on('click', function () {
        var keyword = decodeURI(window.location.href.split("?")[1]);
        window.location.href = "{:url('index/search/search_government')}?" + keyword;
    });

    $(".readMore").eq(0).on('click', function () {
        var keyword = decodeURI(window.location.href.split("?")[1]);
        var value = $("#value").val();
        if (value == '服务市场') {
            window.location.href = "{:url('index/search/search_service')}?" + keyword;
        } else {
            window.location.href = "{:url('index/search/search_trade')}?" + keyword;
        }
    })
    $(".readMore").eq(1).on('click', function () {
        var keyword = decodeURI(window.location.href.split("?")[1]);
        window.location.href = "{:url('index/search/search_store')}?" + keyword;
    })
    $(".readMore").eq(2).on('click', function () {
        var keyword = decodeURI(window.location.href.split("?")[1]);
        window.location.href = "{:url('index/search/search_courses')}?" + keyword;
    })
    $(".readMore").eq(3).on('click', function () {
        var keyword = decodeURI(window.location.href.split("?")[1]);
        window.location.href = "{:url('index/search/search_persons')}?" + keyword;
    })
    $(".readMore").eq(4).on('click', function () {
        var keyword = decodeURI(window.location.href.split("?")[1]);
        window.location.href = "{:url('index/search/search_teachers')}?" + keyword;
    })
    $(".readMore").eq(5).on('click', function () {
        var keyword = decodeURI(window.location.href.split("?")[1]);
        window.location.href = "{:url('index/search/search_government')}?" + keyword;
    })

    /*交易市场与服务市场*/
    $('.sel-btnbox a').on('click', function () {
        $('.sel-btnbox a').removeClass('seled-btn');
        $(this).addClass('seled-btn');
        $("#value").val($(this).text());
        var keyword = decodeURI(window.location.href.split("?")[1]);
        var text = $(this).text();
        postfile(text, keyword);
    });


    $(function () {
        var keyword = decodeURI(window.location.href.split("?")[1]);
        if (keyword == 'undefined') {
            keyword = null;
        }
        postfile('交易市场', keyword);
		$("#keyword").val(keyword);
    });
  

    function postfile(text, keyword) {
        $.ajax({
            type: 'get',
            url: "{:url('api/keyword/search_work')}",
            data: {'text': text, 'keyword': keyword},
            dataType: 'jsonp',
            success: function (msg) {
                if (msg.code == 200) {
                    if (msg.data.market.length != 0 || msg.data.info.length != 0 || msg.data.video.length != 0
                        || msg.data.personnel.length != 0 || msg.data.teachers.length != 0 || msg.data.government.length != 0) {
                        var market = "";//商品
                        var info = "";//店铺
                        var video = "";//视频
                        var personnel = "";//人才
                        var teachers = "";//师资
                        var government = "";//政务
                        var re = /^[0-9]+$/;


                        //商品
                        if (msg.data.market.length != 0) {

                            if ($('.sel-btnbox a').eq(0).text() == msg.data.text) {
                                $('.sel-btnbox a').eq(0).addClass('seled-btn');
                                $('.sel-btnbox a').eq(1).removeClass('seled-btn')
                            } else if ($('.sel-btnbox a').eq(1).text() == msg.data.text) {
                                $('.sel-btnbox a').eq(0).removeClass('seled-btn');
                                $('.sel-btnbox a').eq(1).addClass('seled-btn');
                            }
                            for (var i = 0; i < msg.data.market.length; i++) {
                                if (re.test((i + 1) / 5)) {
                                    market += '<div class="serviceItem mr0">';
                                } else {
                                    market += '<div class="serviceItem">';
                                }
								var price_num = number_format(msg.data.market[i].store, 2, ".", ",");
                                if (msg.data.text == '交易市场') {
                                    market += '<a class="goDetails" ' +
                                        'href="/index.php/index/trade/trade_details.html?id=' + msg.data.market[i].id + '">';
                                    market += '<img src="/Images/tradingMarket/' + msg.data.market[i].image + '"></a><div class="serviceCon">' +
                                        '<span class="prices">￥' + price_num + '起</span>';
                                    market += '<a class="serviceTitle moreline" limit="20" href="/index.php/index' +
                                        '/trade/trade_details.html?id=' + msg.data.market[i].id + '">' + msg.data.market[i].username + '</a>';
                                    market += '<a class="company text_overflow" href="/index.php/index/trade/center.html?'+msg.data.market[i].s_id+'" title="">' + msg.data.market[i].name + '</a>';
                                    market += '<p class="volume">授权量<span class="volumeNum">' + msg.data.market[i].value + '</span>笔</p></div></div>';
                                } else {
                                    market += '<a class="goDetails" ' +
                                        'href="/index.php/index/service/service_details.html?id=' + msg.data.market[i].id + '">';
                                    market += '<img src="/Images/serviceGoods/' + msg.data.market[i].image + '"></a><div class="serviceCon">' +
                                        '<span class="prices">￥' + price_num + '</span>';
                                    market += '<a class="serviceTitle moreline" limit="20" href="/index.php/index' +
                                        '/service/service_details.html?id=' + msg.data.market[i].id + '">' + msg.data.market[i].username + '</a>';
                                    market += '<a class="company text_overflow" href="/index.php/index/trade/center.html?'+msg.data.market[i].s_id+'" title="">' + msg.data.market[i].name + '</a>';
                                    if (msg.data.market[i].rate >= 10000) {
                                        var num = Math.floor(msg.data.market[i].rate / 10000);
                                        market += '<p class="volume">成交量<span class="volumeNum">' + msg.data.market[i].value + '</span>笔</p>' +
                                            '<p class="assess fr">评价<span class="assessNum">' + num + '万+' + '</span>条</p></div></div>';
                                    } else {
                                        market += '<p class="volume">成交量<span class="volumeNum">' + msg.data.market[i].value + '</span>笔</p>' +
                                            '<p class="assess fr">评价<span class="assessNum">' + msg.data.market[i].rate + '</span>条</p></div></div>';
                                    }
                                }
                            }
                            $(".sec-num").eq(0).text('(' + msg.data.market.length + '个)');
                            $(".conBody").eq(0).html(market);
                        } else {
                            $(".con-part").eq(0).attr('style', 'display:none');
                        }

                        //店铺
                        if (msg.data.info.length != 0) {
                            for (var j = 0; j < msg.data.info.length; j++) {
                                if (re.test((j + 1) / 2)) {
                                    info += '<div class="storeitem mr0" all="' + msg.data.info[j].id + '" id="'+msg.data.info[j].user_id+'">';
                                } else {
                                    info += '<div class="storeitem" all="' + msg.data.info[j].id + '" id="'+msg.data.info[j].user_id+'">';
                                }
                                info += '<div class="store-logo"><img src="/Images/Information/' + msg.data.info[j].image + '"></div>' +
                                    '<div class="store-info"><div class="store-name"><p>' + msg.data.info[j].name + '</p></div>' +
                                    '<div class="store-owner"><p>卖家：' + msg.data.info[j].username + '</p></div><div class="store-att">' +
                                    '<p><span class="icons sp1">' + msg.data.info[j].shop_name + '</span><span class="icons icon-sp2"></span>' +
                                    '<span class="icons icon-sp3"></span></p></div><div class="store-in"><p>' +
                                    '<span>销量' + msg.data.info[j].shop_volume + '</span>' +
                                    '<span>共' + msg.data.info[j].count + '件商品</span></p></div>' +
                                    '<div class="store-scope"><p>主营：' + msg.data.info[j].scope + '</p></div>' +
                                    '<div class="store-btn"><a href="/index.php/index/trade/center.html?' + msg.data.info[j].id + '">进店逛逛</a>' +
                                    '<a class="contactStore" href="javascript:;">联系卖家</a></div></div></div>';
                            }
                            $(".sec-num").eq(1).text('(' + msg.data.info.length + '个)');
                            $(".conBody").eq(1).html(info);


                            /*联系卖家*/
                            $('.contactStore').on('click', function () {
                                var id = $(this).parents('div.storeitem').attr('all');
								var to_uid = $(this).parents("div.storeitem").attr('id');
                                var userinfo = $.cookie('userinfo');
                                if (userinfo) {
                                    var user_login = $.base64.decode(userinfo).split(",");
                                    var from_uid = user_login[0];
                                    layer.open({
                                        type: 2,
                                        title: '联系卖家',
                                        fix: false,
                                        maxmin: true,
                                        shadeClose: true,
                                        scrollbar: false,
                                        area: ['560px', '490px'],
                                        content: 'contact.html?id=' + id,
                                        btn: ['发送', '取消'],
                                        yes: function (index, layero) {
                                            //do something

                                            var body = layer.getChildFrame('body', index);
                                            // var iframeWin = window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
                                            //得到iframe页的body内容
                                            var content = body.find('#news_title').val();
                                            layer.close(index);//如果设定了yes回调，需进行手工关闭
                                            if (content != '' || title != '') {
                                                $.ajax({
                                                    type: "get",
                                                    url: "{:url('api/trading/trading_chat')}",
                                                    data: {
                                                        'to_uid': to_uid,
                                                        'content': content,
                                                        'from_uid': from_uid
                                                    },
                                                    dataType: 'jsonp',
													beforeSend: function () {
													var index = layer.load(1, {
														shade: [0.1, '#333333'] //0.1透明度的白色背景
													});
													},
                                                    success: function (msg) {
                                                        layer.closeAll();
                                                        if (msg.code == 200) {
                                                            layer.msg('发送成功！', {icon: 1}, function () {
                                                            });
                                                        }
                                                        if (msg.code == 1000) {
                                                            layer.msg('发送失败！', {icon: 5});
                                                        }
                                                    }
                                                });
                                            } else {
                                                layer.msg('不能为空！', {icon: 5});
                                            }
                                        }
                                    });
                                } else {
                                    layer.msg('你还没有登录！', {icon: 51});
                                }
                            });

                        } else {
                            $(".con-part").eq(1).attr('style', 'display:none');
                        }

                        //视频
                        if (msg.data.video.length != 0) {
                            for (var q = 0; q < msg.data.video.length; q++) {
                                if (re.test((q + 1) / 4)) {
                                    video += '<div class="sectionItem mr0">';
                                } else {
                                    video += '<div class="sectionItem">';
                                }
                                video += '<div class="imgBox"><a class="links" href="/index.php/index' +
                                    '/train/courses_details.html?id=' + msg.data.video[q].id + '">' +
                                    '<img width="280px;" height="210px;" src="/Images/Cover/' + msg.data.video[q].pic + '"></a></div><div class="courseCon">' +
                                    '<a class="links courseTitle text_overflow" href="/index.php/index' +
                                    '/train/courses_details.html?id=' + msg.data.video[q].id + '">' + msg.data.video[q].title + '</a>' +
                                    '<p class="Episodes">共<span class="EpisodesNum">' + msg.data.video[q].episode + '</span>集</p><p class="learner">' +
                                    '<span class="learnerNum">' + msg.data.video[q].views + '</span>人学习</p>' +
                                    '<p class="praise"><span class="icons icon-praise"></span>' + msg.data.video[q].likes + '</p></div></div>';
                            }
                            $(".sec-num").eq(2).text('(' + msg.data.video.length + '个)');
                            $(".conBody").eq(2).html(video);
                        } else {
                            $(".con-part").eq(2).attr('style', 'display:none');
                        }

                        //相关人才
                        if (msg.data.personnel.length != 0) {
                            for (var w = 0; w < msg.data.personnel.length; w++) {
                                var arr = msg.data.personnel[w].label.split(" ");
                                var label = "";
                                for (var m = 0; m < arr.length; m++) {
                                    if (arr[m]) {
                                        label += '<span class="labels">' + arr[m] + '</span>';
                                    }
                                }
                                if (re.test((w + 1) / 3)) {
                                    personnel += '<div class="personInfo sectionItem mr0">';
                                } else {
                                    personnel += '<div class="personInfo sectionItem">';
                                }
                                personnel += '<div class="userImg"><a class="links" href="/index.php/index' +
                                    '/train/persons_details.html?type=1&id=' + msg.data.personnel[w].id + '">' +
                                    '<img src="/static/web/images/76.png" class="icon-wapper">' +
                                    '<img src="/Images/Talent/' + msg.data.personnel[w].img_url + '" class="icon"></a></div>' +
                                    '<a class="links username" href="/index.php/index' +
                                    '/train/persons_details.html?type=1&id=' + msg.data.personnel[w].id + '">' + msg.data.personnel[w].talentname + '</a>' +
                                    '<p class="position">' + msg.data.personnel[w].rolename + '</p>';
                                personnel += '<p class="position">' + label + '</p>';
                                personnel += '<div class="areas moreline" limit="54">' + msg.data.personnel[w].field + '</div></div>';
                            }
                            $(".sec-num").eq(3).text('(' + msg.data.personnel.length + '个)');
                            $(".conBody").eq(3).html(personnel);
                        } else {
                            $(".con-part").eq(3).attr('style', 'display:none');
                        }

                        //相关师资
                        if (msg.data.teachers.length != 0) {
                            for (var r = 0; r < msg.data.teachers.length; r++) {
                                var arr = msg.data.teachers[r].label.split(" ");
                                var label = "";
                                for (var m = 0; m < arr.length; m++) {
                                    if (arr[m]) {
                                        label += '<span class="labels">' + arr[m] + '</span>';
                                    }
                                }
                                if (re.test((r + 1) / 3)) {
                                    teachers += '<div class="personInfo sectionItem mr0">';
                                } else {
                                    teachers += '<div class="personInfo sectionItem">';
                                }
                                teachers += '<div class="userImg"><a class="links" href="/index.php/index' +
                                    '/train/persons_details.html?type=2&id=' + msg.data.teachers[r].id + '">' +
                                    '<img src="/static/web/images/76.png" class="icon-wapper">' +
                                    '<img src="/Images/Talent/' + msg.data.teachers[r].img_url + '" class="icon"></a></div>' +
                                    '<a class="links username" href="/index.php/index' +
                                    '/train/persons_details.html?type=2&id=' + msg.data.teachers[r].id + '">' + msg.data.teachers[r].talentname + '</a>' +
                                    '<p class="position">' + msg.data.teachers[r].rolename + '</p>';
                                teachers += '<p class="position">' + label + '</p>';
                                teachers += '<div class="areas moreline" limit="54">' + msg.data.teachers[r].field + '</div></div>';
                            }
                            $(".sec-num").eq(4).text('(' + msg.data.teachers.length + '个)');
                            $(".conBody").eq(4).html(teachers);
                        } else {
                            $(".con-part").eq(4).attr('style', 'display:none');
                        }
                        /*限制字符个数*/
                        $(".moreline").each(function () {
                            var val = $(this).attr('limit');
                            var maxwidth = val;
                            if ($(this).text().length > maxwidth) {
                                $(this).text($(this).text().substring(0, maxwidth));
                                $(this).html($(this).html() + '...');
                            }
                        });

                        //相关政务
                        if (msg.data.government.length != 0) {
                            for (var y = 0; y < msg.data.government.length; y++) {
                                var src = msg.data.government[y].pic;
                                government += '<div class="sectionItem"><div class="sectionImgbox fl">' +
                                    '<img class="sectionImg" src="' + src + '"></div>' +
                                    '<a class="sectionTitle text_overflow fl" href="/index.php/index' +
                                    '/government/government_details.html?id=' + msg.data.government[y].id + '">' + msg.data.government[y].title + '</a>' +
                                    '<p class="sectionSummary moreline fl" limit="90">' + msg.data.government[y].abstract + '</p><div class="sectionTags fl">' +
                                    '<p class="time"><span class="icons icon-time"></span>' + getMyDate(msg.data.government[y].time * 1000) + '</p>' +
                                    '<p class="view"><span class="icons icon-view"></span>' + msg.data.government[y].views + '</p>' +
                                    '<p class="praise"><span class="icons icon-praise"></span>' + msg.data.government[y].likes + '</p>' +
                                    '<p class="collect"><span class="icons icon-collect"></span>' + msg.data.government[y].collect + '</p></div></div>';
                            }
                            $(".sec-num").eq(5).text('(' + msg.data.government.length + '个)');
                            $(".conBody").eq(5).html(government);
                        } else {
                            $(".con-part").eq(5).attr('style', 'display:none');
                        }
                    } else {
                        $(".con-part").attr('style', 'display:none');
                        $(".nodatas").attr('style', 'display:block');
                    }
                }
            }
        })
    }
</script>
{/block}
